package com.ycf.demo1.service;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;

public class Register {

    private String jsonString;
    public String userRegister(String username, String password,String qq) throws Exception{
        String info = "";
        String path="http://192.168.39.195/user/register";
        //参数直接加载url后面
        path += "?username=" + username + "&password=" + password + "&qq=" + qq;
        System.out.println(path);
        URL url=new URL(path);
        HttpURLConnection conn=(HttpURLConnection) url.openConnection();
        conn.setRequestMethod("GET");
        conn.setConnectTimeout(5000);
        if(conn.getResponseCode()==200){
            InputStream is=conn.getInputStream();
            //将输入流转换成字符串
            ByteArrayOutputStream baos=new ByteArrayOutputStream();
            byte [] buffer=new byte[1024];
            int len=0;
            while((len=is.read(buffer))!=-1){
                baos.write(buffer, 0, len);
            }
            jsonString=baos.toString();
            baos.close();
            is.close();

        }
        //转换成json数据处理
        System.out.println("jsonString = " + jsonString);
        return jsonString;

    }

}
